import { HttpModule } from '@nestjs/axios';
import { Global, Module } from '@nestjs/common';
import { EventEmitterModule } from '@nestjs/event-emitter';
import { ScheduleModule } from '@nestjs/schedule';
import { ThrottlerModule } from '@nestjs/throttler';

import { isDev } from '~/global/env';

import { HelperModule } from './helper/helper.module';
import { LoggerModule } from './logger/logger.module';

import { RedisModule } from './redis/redis.module';
import { DatabaseModule } from './database/database.module';
import { MongodbModule } from './mongodb/mongodb.modles';

@Global()
@Module({
  imports: [
    // logger
    LoggerModule.forRoot(),
    // http
    HttpModule,
    // schedule
    ScheduleModule.forRoot(),
    // rate limit
    ThrottlerModule.forRoot([
      {
        limit: 20,
        ttl: 60000,
      },
    ]),
    EventEmitterModule.forRoot({
      wildcard: true,
      delimiter: '.',
      newListener: false,
      removeListener: false,
      maxListeners: 20,
      verboseMemoryLeak: isDev,
      ignoreErrors: false,
    }),
    // redis
    RedisModule,
    // helper
    HelperModule,
    //数据库
    MongodbModule,
    DatabaseModule,
  ],
  exports: [HttpModule, RedisModule, HelperModule],
})
export class SharedModule {}
